CREATE TABLE [dbo].[OpportunityMain]
(
[OpportunityKey] [uniqueidentifier] NOT NULL CONSTRAINT [DF_OpportunityMain_OpportunityKey] DEFAULT (newid()),
[OpportunityTypeKey] [uniqueidentifier] NOT NULL,
[Id] [int] NOT NULL CONSTRAINT [DF_OpportunityMain_Id] DEFAULT ((1)),
[Description] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
[OpportunityOwnerGroupKey] [uniqueidentifier] NOT NULL,
[OpportunityContactGroupKey] [uniqueidentifier] NOT NULL,
[ProspectKey] [uniqueidentifier] NOT NULL,
[CurrentActionPlanStageName] [nvarchar] (200) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_OpportunityMain_CurrentActionPlanStageName] DEFAULT (''),
[WinProbability] [decimal] (12, 2) NOT NULL CONSTRAINT [DF_OpportunityMain_WinProbability] DEFAULT ((0)),
[ActionManifest] [ntext] COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
[OpportunityStatusCode] [int] NOT NULL,
[SourceCodeKey] [uniqueidentifier] NULL,
[ExpirationDate] [datetime] NULL,
[UpdatedByUserKey] [uniqueidentifier] NOT NULL,
[UpdatedOn] [datetime] NOT NULL,
[CreatedByUserKey] [uniqueidentifier] NOT NULL,
[CreatedOn] [datetime] NOT NULL,
[SystemEntityKey] [uniqueidentifier] NOT NULL,
[AccessKey] [uniqueidentifier] NOT NULL,
[MarkedForDeleteOn] [datetime] NULL,
[ProductKey] [uniqueidentifier] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [PK_OpportunityMain] PRIMARY KEY CLUSTERED ([OpportunityKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [AK_OpportunityMain_AccessKey] ON [dbo].[OpportunityMain] ([AccessKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_CreatedByUserKey] ON [dbo].[OpportunityMain] ([CreatedByUserKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_OpportunityContactGroupKey] ON [dbo].[OpportunityMain] ([OpportunityContactGroupKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_OpportunityOwnerGroupKey] ON [dbo].[OpportunityMain] ([OpportunityOwnerGroupKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_OpportunityStatusCode] ON [dbo].[OpportunityMain] ([OpportunityStatusCode]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_OpportunityTypeKey] ON [dbo].[OpportunityMain] ([OpportunityTypeKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_ProductKey] ON [dbo].[OpportunityMain] ([ProductKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_ProspectKey] ON [dbo].[OpportunityMain] ([ProspectKey]) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [IX_OpportunityMain_UpdatedByUserKey] ON [dbo].[OpportunityMain] ([UpdatedByUserKey]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_AccessMain] FOREIGN KEY ([AccessKey]) REFERENCES [dbo].[AccessMain] ([AccessKey])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_ContactMain] FOREIGN KEY ([ProspectKey]) REFERENCES [dbo].[ContactMain] ([ContactKey])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_OpportunityStatusRef] FOREIGN KEY ([OpportunityStatusCode]) REFERENCES [dbo].[OpportunityStatusRef] ([OpportunityStatusCode])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_OpportunityType] FOREIGN KEY ([OpportunityTypeKey]) REFERENCES [dbo].[OpportunityType] ([OpportunityTypeKey])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_UniformRegistry] FOREIGN KEY ([OpportunityKey]) REFERENCES [dbo].[UniformRegistry] ([UniformKey])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_UserMain_CreatedBy] FOREIGN KEY ([CreatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
ALTER TABLE [dbo].[OpportunityMain] ADD CONSTRAINT [FK_OpportunityMain_UserMain_UpdatedBy] FOREIGN KEY ([UpdatedByUserKey]) REFERENCES [dbo].[UserMain] ([UserKey])
GO
GRANT REFERENCES ON [dbo].[OpportunityMain] TO [IMIS]
GRANT SELECT ON [dbo].[OpportunityMain] TO [IMIS]
GRANT INSERT ON [dbo].[OpportunityMain] TO [IMIS]
GRANT DELETE ON [dbo].[OpportunityMain] TO [IMIS]
GRANT UPDATE ON [dbo].[OpportunityMain] TO [IMIS]
GO